package com.fjb.controller.banner;

import java.time.LocalDateTime;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fjb.common.entity.HttpCode;
import com.fjb.common.entity.JsonResult;
import com.fjb.common.entity.JsonTotalResult;
import com.fjb.common.entity.PageQuery;
import com.fjb.common.global.GlobalConfig;
import com.fjb.controller.base.BaseController;
import com.fjb.pojo.banner.BannerInfo;
import com.fjb.pojo.banner.query.BannerInfoQuery;
import com.fjb.pojo.login.LoginUserInfo;
import com.fjb.pojo.product.ProductCategory;
import com.fjb.pojo.user.SysUser;
import com.fjb.service.banner.BannerInfoService;

/**
 * @Description:广告信息
 * @author hemiao
 * @time:2020年1月31日 下午9:51:34
 */
@Controller
@RequestMapping("/bannerInfo")
public class BannerInfoController extends BaseController{
	
	@Autowired
	private BannerInfoService bannerInfoService;
	
	/**
	 * @Description:显示分页列表
	 * @param request
	 * @return
	 * ModelAndView
	 * @exception:
	 * @author: hemiao
	 * @time:2019年12月28日 下午5:58:26
	 */
	@RequestMapping(value="/showPageList")
    public ModelAndView showPageList(HttpServletRequest request) {
    	ModelAndView mv = new ModelAndView();	
    	mv.setViewName("/banner/banner_info_list");
    	mv.addObject(FILE_SERVICE_LOCATION, GlobalConfig.FILE_SERVICE_LOCATION);
    	return mv;
    }
	
	/**
	 * @Description:分页列表查询
	 * @param request
	 * @param bannerInfoQuery
	 * @param pageQuery
	 * @return
	 * JsonTotalResult<List<BannerInfo>>
	 * @exception:
	 * @author: hemiao
	 * @time:2020年1月31日 下午9:53:00
	 */
	@RequestMapping(value = "/selectPageList")
    @ResponseBody
    public JsonTotalResult<List<BannerInfo>> selectPageList(HttpServletRequest request,BannerInfoQuery bannerInfoQuery
    		, PageQuery pageQuery){
        return bannerInfoService.selectPageList(bannerInfoQuery,pageQuery);
    }
	
	/**
	 * @Description:修改广告状态
	 * @param request
	 * @param bannerId
	 * @param bannerStatus
	 * @return
	 * JsonResult<Boolean>
	 * @exception:
	 * @author: hemiao
	 * @time:2020年3月2日 下午8:25:21
	 */
	@RequestMapping(value = "/updateStatus")
    @ResponseBody
    public JsonResult<Boolean> updateStatus(HttpServletRequest request,Integer bannerId,Integer bannerStatus){
		HttpCode httpCode = HttpCode.PARAM_VERIFICATION;
		if(bannerId==null||bannerStatus==null) {	
			return new JsonResult<Boolean>(null, httpCode);
		}
		LoginUserInfo userInfo = getUserInfo(request);
		SysUser sysUser = userInfo.getSysUser();
		Integer userId = sysUser.getId();
		
		BannerInfo bi = new BannerInfo();
		bi.setId(bannerId);
		bi.setBannerStatus(bannerStatus);
		bi.setUpdateUserId(userId);
		bi.setUpdateTime(LocalDateTime.now());
		boolean b = bannerInfoService.updateById(bi);
		return new JsonResult<Boolean>(b, HttpCode.SUCCESS);
	}
}
